#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>

using namespace std;

int xiangl(vector<long int> u);

///判断同花色的卡牌最多有多少张
//返回最多的张数及其花色
int maxcard(vector<long int> c,int &maxc)
{
    int max=0;
    int maxcolor=0;
    for(int i=0;i<c.size();i++)
    {
        int count=0;
        for(int j=0;j<c.size()-i;j++)
        {
            if(c[i]==c[j])
            {
                count++;
            }
        }
        if(count>max)
        {
            max=count;
            maxcolor=c[i];
        }
    }
    maxc=max;
    return maxcolor;
}

//判断同花色中点数相连的最多有多少张
//返回最多的张数
int maxsum(vector<long int> c,vector<long int> u,int maxcolor)
{
    int max=0;
    vector<long int> v;
    for(int i=0;i<c.size();i++)
    {
        if(c[i]==maxcolor)
        {
            v.push_back(u[i]);
        }
    }
    max=xiangl(v);

    return max;
}

//判断点数是否相连
int xiangl(vector<long int> u)
{
    int left = 0, right = 0;
    int maxLen = 1;
    while (right < u.size() - 1) {
        if (u[right] + 1 == u[right + 1]) {
            right++;
        } else {
            maxLen = max(maxLen, right - left + 1);
            left = right + 1;
            right = left;
        }
    }
    maxLen = max(maxLen, right - left + 1);

    return maxLen;
}

int main()
{
    FILE *fp = fopen("card.in", "r");
    FILE *fc = fopen("card.out", "w");

    //n为卡牌数量, c为卡牌的花色, u为卡牌的点数
    int n=0;
    vector<long int> c;
    vector<long int> u;
    fscanf(fp,"%d",&n);

    for(int i=0;i<n;i++)
    {
        int ls1,ls2;
        fscanf(fp,"%d %d",&ls1,&ls2);
        c.push_back(ls1);
        u.push_back(ls2);
    }

    //判断同花色最多有多少张
    //max1为最多的张数，maxc为最多张数的花色
    int maxc=0,max1=0;
    maxc=maxcard(c,max1);

    //判断同花色中点数相连的最多有多少张
    //max2为最多的张数
    int max2=0;
    max2=maxsum(c,u,maxc);
    max2=u.size()-max1-max2;

    //输出结果
    fprintf(fc,"%d",max1+max2);

    fclose(fp);
    fclose(fc);

    return 0;
}